import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react-swc";
import svgr from "vite-plugin-svgr";

const mode = process.env.VITE_TITLE || "development";
const env = loadEnv(mode, process.cwd());

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react(), svgr({ svgrOptions: { icon: true } })],
  server: {
    port: Number(env.VITE_PORT),
    proxy: {
      [env.VITE_API_PREFIX]: {
        target: env.VITE_API_BASE_URL,
        changeOrigin: false,
        rewrite: (path) =>
          path.replace(new RegExp(`^${env.VITE_API_PREFIX}`), ""),
      },
      [env.VITE_WS_PREFIX]: {
        target: env.VITE_WS_BASE_URL,
        ws: true,
      },
    },
  },
  resolve: {
    alias: {
      "@": "/src",
    },
  },
});
